
$(function () {
    $('.sign-way-open').click(function () {
        $('.sign-way').show();
    })
    $('.sign-way-close').click(function () {
        $('.sign-way').hide();
    })
})

var app = new Vue({
    el: '#body',

    data() {
        return {
            id : $config.GetQueryString('id') || '',
            infos: ''
        }
    },
    created(){
        this.getInfos()
    },
    mounted() {
        DOMINIT();
    },
    methods: {
        getInfos (){
            this.common().http(this, {
                url: `/detail/db/2018lyswxj/id/${this.id}`,
                success(json) {
                    this.infos = json.data;
                }
            })
        },
        // 投票
        voting(){
            this.common().http(this, {
                url: `/jsonp4piao/db/2018lyswxj/id/${this.id}`,
                lock:true,
                success(json) {
                    if(json.info=='投票已结束'){
                        swal({
                            title: json.info,
                            type: "warning"
                        })
                    }else{
                        this.infos.piao++;
                        swal({
                            title: json.msg,
                            type: "success"
                        })
                    }

                }
            })
        }
    }
})

function DOMINIT() {

    // 跳转到指定位置
    function click_scroll(ele) {
        var scroll_offset = $(ele).offset(); //得到pos这个div层的offset，包含两个值，top和left
        $("body,html").animate({
            scrollTop:scroll_offset.top-200 //让body的scrollTop等于pos的top，就实现了滚动
        },300);
    }

    // 导航跳转指定位置
    $('nav .list a , nav .logo').on('click',function () {
        var ele = $(this).data('togo');
        // if(ele) click_scroll(ele);
        if(ele=='body'){
            location.href='index.html';
        }else{
            location.href='index.html?name='+ele;
        }
    })

    //监听导航栏
    function showNav() {
        var top = $(document).scrollTop(),
            ishas = $('nav').hasClass('scroll');
        if(top>0){
            if(!ishas) $('nav').addClass('scroll');
        }else{
            if(ishas) $('nav').removeClass('scroll');
        }
    }
    $(window).scroll(function () {
        showNav();
    })
    showNav();
}